package com.kotlin.demo.泛型


data class ObjectClass1(val name:String,val age: Int,val study: String)
data class ObjectClass2(val name:String,val age: Int,val study: String)
data class ObjectClass3(val name:String,val age: Int,val study: String)

class KtBase112 {

    val objectClasses : List<Any> = listOf(
        ObjectClass1("name1", 1, "c"),
        ObjectClass2("name2", 2, "c++"),
        ObjectClass3("name2", 2, "c#")
    )

    //如果传入的类型有那么就返回这个类型,如果没有就返回默认值
    inline fun <reified T> randomOrDefault(defaultLambdaAction:() -> T){

        val item = objectClasses.shuffled().first()

        item.takeIf { it is T } as T ?: defaultLambdaAction()




    }


}